package com.converter;
import java.util.Map;
import org.apache.struts2.util.StrutsTypeConverter;
import com.bean.Point;

public class PointConverter extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {

		Point point = new Point();
		String[] values = arg1[0].split(",");
		int x = Integer.parseInt(values[0].trim());
		int y = Integer.parseInt(values[1].trim());
		point.setX(x);
		point.setY(y);
		return point;
	}
	@Override
	public String convertToString(Map arg0, Object arg1) {
		Point point = (Point) arg1;
		int x = point.getX();
		int y = point.getY();
		String result = "<x= " + x + " ,  y=" + y + " >";
		return result;
	}
}
